import { getAreaList, getDeptList } from '@/api/illegal'

export const useIllegalStore = defineStore('useillegal', () => {
	let leaderList = []
	let deptList = []
	let areaOptions = []
	const pushItem = (obj: any, data: any) => {
		for (let i = 0; i < data.length; i++) {
			obj[i] = {
				label: '',
				value: '',
			}
			if (data[i].users) {
				obj[i].children = []
				pushItem(obj[i].children, data[i].users)
			}
			obj[i].label = data[i].deptName
			obj[i].value = data[i].id
		}
	}
	const getLeaderDeptList = () => {
		getDeptList({ type: 'leaderDept', deptId: '510185000000' }).then((res) => {
			pushItem(leaderList, res.data)
		})
		getDeptList({ type: 'user', deptId: '510185000000' }).then((res) => {
			res.data.forEach((item) => {
				deptList.push({
					value: item.id,
					label: item.deptName,
				})
			})
		})

		getAreaList().then((res) => {
			const map = res.data
			for (let item in map) {
				areaOptions.push({ value: item, label: map[item] })
			}
		})
	}

	const twoNonType = ['', '国有土地违建', '集体土地违建', '自建房扩建', '违章搭建']
	const dealStatus = ['处置中', '处置完成', '超期处置中', '超期已完成']
	// 处置状态
	const dealOptions = [
		{
			value: null,
			label: '全部',
		},
		{
			value: 0,
			label: '处置中',
		},
		{
			value: 1,
			label: '处置完成',
		},
		{
			value: 2,
			label: '超期处置中',
		},
		{
			value: 3,
			label: '超期已完成',
		},
	]
	// 违建类别
	const typeOptions = [
		{
			value: '1',
			label: '国有土地违建',
		},
		{
			value: '2',
			label: '集体土地违建',
		},
		{
			value: '3',
			label: '自建房扩建',
		},
		{
			value: '4',
			label: '违章搭建',
		},
	]
	return {
		dealOptions,
		typeOptions,
		twoNonType,
		dealStatus,
		getLeaderDeptList,
		leaderList,
		deptList,
		areaOptions,
	}
})
